import Toast from "@vant/weapp/toast/toast";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: true,
    phone: "17864117674",
    password: "",
    code: undefined,
    token: undefined,
    refreshToken: undefined,
    time: 6 * 1000,
    timeData: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  onTimefinished() {
    this.setData({
      show: true,
    });
  },
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
    // console.log(e.detail);
  },
  onInputpho(e) {
    this.setData({
      // phone: e.detail.value,
      phone: 123,
    });
  },
  onInputpsd(e) {
    this.setData({
      password: e.detail.value,
    });
  },
  async getPhone() {
    if (this.data.phone.trim() == "") {
      return Toast("请填写正确手机号");
    }
    this.setData({
      show: false,
      value: this.data.value,
    });
    Toast.loading({
      message: "加载中...",
      forbidClick: true,
      duration: 1,
    });
    let res = await wx.$http.get("/code", {
      mobile: this.data.phone,
    });
    let code = res.data.data.code;
    this.setData({
      code: code,
    });
  },

  async goLogin() {
    let res1 = await wx.$http.post("/login", {
      mobile: this.data.phone,
      code: this.data.code,
    });
    const token = res1.data.data.token;
    const refreshToken = res1.data.data.refreshToken;
    this.setData({
      token: token,
      refreshToken: refreshToken,
    });
    wx.setStorageSync("token", {
      myToken: token,
      myrefreshToken: refreshToken,
    });
    // console.log(wx.getStorageSync('token'));
    wx.navigateTo({
      url: "/pages/userInfo/userInfo",
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //写一个定时器
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
